package android_rteditor.customsortricheditor.editor;

/**
 * Created by chenxunlin01 on 2017/8/16.
 */

public class EditorItemFactory {

    private static EditorItemFactory factory;

    public static final int EDITOR_ITEM_EDITTEXT = 1;
    public static final int EDITOR_ITEM_IMAGE = 2;
    public static final int EDITOR_ITEM_CHECKBOX = 3;
    public static final int EDITOR_ITEM_AUDIO = 4;

    private EditorItemFactory() {
    }

    public synchronized static EditorItemFactory newstance() {
        if (factory == null) {
            factory = new EditorItemFactory();
        }
        return factory;
    }

    public static IEditorItem createEditorItem(RichEditorController controller, int type) {
        switch (type) {
            case EDITOR_ITEM_EDITTEXT:
                return createRichEditText(controller);
            case EDITOR_ITEM_IMAGE:
                return createRichImage(controller);
            case EDITOR_ITEM_CHECKBOX:
                return createCheckboxView(controller);
            case EDITOR_ITEM_AUDIO:
                return createRichAudioView(controller);
        }
        return null;
    }

    private static RichEditText createRichEditText(RichEditorController controller) {
        RichEditText editText = new RichEditText(controller.getActivity(), controller, controller
                .getFocusChangeListener());
        return editText;
    }

    private static RichImage createRichImage(RichEditorController controller) {
        RichImage image = new RichImage(controller.getActivity());
        return image;
    }

    private static CheckboxView createCheckboxView(RichEditorController controller) {
        CheckboxView checkboxView = new CheckboxView(controller.getActivity(), controller, controller
                .getFocusChangeListener());
        return checkboxView;
    }

    private static RichAudio createRichAudioView(RichEditorController controller) {
        RichAudio richAudio = new RichAudio(controller.getActivity());
        return richAudio;
    }

}
